<template>
  <div class="main-container">
    <div class="ht100 pos-div">
      <div v-for="(item,index) in formdata" :key="index">
        <div class="mt10" style=" display: flex;border-bottom: 1px solid #ebedf0;">
          <div class="blue_item" />
          <span class="font15" style="display: flex; line-height: 33px;margin-left:5px;  flex:1;">{{ item.name }}</span>
        </div>
        <div style="padding: 10px;font-size: 16px;">{{item.displayOrder}}.{{item.value}}
          <van-radio-group v-model="item.result" direction="horizontal" style='margin-top: 10px;margin-left: 10px'>
            <van-radio name="1">是</van-radio>
            <van-radio name="0">否</van-radio>
          </van-radio-group>
        </div>
        <el-input style="padding: 0px 15px"
            type="textarea"
            :rows="2"
            placeholder="备注"
            v-model="item.beizhu">
        </el-input>
      </div>
      </div>
    <div  style="margin-top: 20px">
      <div class="pof-btn" >
        <van-button style="background: #00a0e9;color: white" class="bg-theme color-f ht46 font15 flex1" native-type="submit" @click.native="onSubmit('pass')">提交</van-button>
      </div>
    </div>
  </div>
</template>

<script>
//判断是否等于上一个模块的名称，来显示隐藏大模块
import {req,reqNoAction} from '@/api/gettodo';
import { mapGetters } from "vuex";
import {Notify, Toast} from 'vant';
import util from '@/assets/js/public';
export default {
  name: "newDetail",
  data() {
    return {
      formdata: [],
      operationList:[],
      gridName:''
    };
  },
  created() {},
  activated() {
    this.getData();
    this.getGridName();
  },
  methods: {
    onSubmit(type) {
      this.operationList=[]
      var haveEditAll=true
      for (var i in this.formdata){
        if (this.formdata[i].result=='0'||this.formdata[i].result=='1'){
          console.log('去提交'+this.formdata[i].result)
          this.operationList.push({ dictId: this.formdata[i].id,
            dictValue: this.formdata[i].value,
            operationInfo:this.formdata[i].result,
            remarkInfo:this.formdata[i].beizhu})
        }else {
          haveEditAll=false
          break
        }
      }
      if (haveEditAll==true){
        console.log('去提交'+JSON.stringify(this.operationList))
        Toast.loading({
          message: "提交中...",
          forbidClick: false,
        });
        req('djfupt','usZwrgdyInfo$insertInfo$api',
            Object.assign({
                  kv: {
                    "source": 'MOBILE',
                    "currentUserCode": util.encrypt(this.user.userName),
                  },
                  body: {
                    "operationList": this.operationList,
                    "gridName":this.gridName
                  }
                }
            ))
            .then((result) => {
              Toast.clear();
              if (!result.data) {
                Notify(result.message);
                return;
              }
              Notify({ type: 'success', message: '提交成功' })
              this.$router.replace(
                  {
                    name:'mainview',
                    query:{
                    }
                  }
              )
            })
      }else {
        Notify({ type: 'warning', message: '请填写所有项目再提交' })
      }
    },
    getData() {
      Toast.loading({
        message: "加载中...",
        forbidClick: false,
      });
      reqNoAction('djfupt','sys$dictValue$findDictValue$api',
          Object.assign({
                kv: {
                  "source": 'MOBILE',
                  "currentUserCode": util.encrypt(this.user.userName),
                  "dictType": 'XTGJ_ZWRGDY_TYPE',
                },
                body: {
                  "dictType": 'XTGJ_ZWRGDY_TYPE',
                }
              }
          ))
          .then((result) => {
            Toast.clear();
            if (!result.data) {
              Notify(result.message);
              return;
            }
            this.formdata=[]
            if (result.data.data) {
              this.formdata=result.data.data
            }
          })
    },
    getGridName(){
      Toast.loading({
        message: "加载中...",
        forbidClick: false,
      });
      req('djfupt','usZwrgdyInfo$getGridName$api',
          Object.assign({
                kv: {
                  "source": 'MOBILE',
                  "currentUserCode": util.encrypt(this.user.userName),
                }
              }
          ))
          .then((result) => {
            Toast.clear();
            if (!result.data) {
              Notify(result.message);
              return;
            }
            if (result.data.data) {
              this.gridName=result.data.data.gridName
            }
          })
    }
  },
  computed: {
    ...mapGetters(["user"]),
  },
  watch: {

  },
};
</script>

<style>

</style>